home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11950 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  3.7 KB

  1. Path: tezcat.com!news
  2. From: Max Rubinstein <maxrubin@tezcat.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: MSVC++ Header files/Linker error help needed
  5. Date: Sun, 17 Mar 1996 00:12:12 -0600
  6. Organization: Tezcat Communications - Chicago
  7. Message-ID: <314BAD3C.3C01@tezcat.com>
  8. References: <4id68p$qa5@news.csus.edu>
  9. NNTP-Posting-Host: maxrubin.tezcat.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (Win95; I)
  14.  
  15. Mike wrote:
  16. > Please help!  I am a very frustrated begenning C++ programmer trying to use
  17. > MSVC++ 4.0.  I am trying to follow good programming practice by declaring my
  18. > objects and functions in a header file, but I'm having serious trouble.  The
  19. > stuff I'm doing is very simple and shown below:
  20. > **** header file CTest.h****
  21. > class CTest
  22. > {
  23. >   private:
  24. >     int I;
  25. >   public:
  26. >     CTest();
  27. >     CTest(int ToI);
  28. >     void SetI(int ToI);
  29. >     int GetI();
  30. >     };
  31. > **** Implementation file CTest.cpp ****
  32. > #include "CTest.h"
  33. > CTest::CTest(){};
  34. > CTest::CTest(int ToI)
  35. >  {
  36. >     I = ToI;
  37. >     };
  38. > void CTest::SetI(int ToI)
  39. > {
  40. >   I = ToI;
  41. >   };
  42. > int CTest::GetI()
  43. > {
  44. >   return I;
  45. >   };
  46. > **** main file Main.cpp ****
  47. > #include "CTest.h"
  48. > #include <iostream.h>
  49. > void main()
  50. > {
  51. >   CTest TestObj;
  52. >   TestObj.SetI(9);
  53. >   cout << TestObj.GetI();
  54. >   };
  55. >   This is very basic stuff, or so I thought.  If I add the Main.cpp and the
  56. > CTest.cpp to the console mode project and build it, MSVC++ runs fine, and I
  57. > get no errors.
  58. > However, when I create a Windows program (MDI, SDI, Dialog-based) and add the
  59. > CTest.cpp to the project and the CTest.h to a simple dialog class that I
  60. > create, upon building the project I receive the following message:
  61. > :\Projects\test\CTest.cpp(23) : fatal error C1010: unexpected end of file
  62. > while looking for precompiled header directive
  63. >  If I DO NOT add the CTest.cpp to the project, I receive the following errors:
  64. > MyDlg.obj : error LNK2001: unresolved external symbol "public: void __thiscall
  65. > CTest::SetI(int)"(?SetI@CTest@@QAEXH@Z)
  66. > MyDlg.obj : error LNK2001: unresolved external symbol "public: __thiscall
  67. > CTest::CTest(void)"(??0CTest@@QAE@XZ)
  68. >   From what I can tell, the compiler cannot or will not find the
  69. > #include "CTest.h"  directive when I have included the cpp file.  I have
  70. > placed the two CTest files (CTest.h and CTest.cpp) in the project directory,
  71. > added the project directory to the list of directories (under Options) and yet
  72. > it STILL won't find the header file.
  73. >   I have tried to follow the examples of other files which are included in the
  74. > project, such as the dialog.h and dialog.cpp (which have no problems
  75. > building), and yet I continue to get the same error
  76. > .
  77. > Can someone please tell me what I'm doing wrong?!!!
  78. >  Before abandoning my investment and switching to Delphi 2.0, I'd like to at
  79. > least try to figure out what my mistake is, if any.  Again, I am relatively
  80. > new to programming in C++ so I may be missing something really basic here.
  81. > Readers should note that I am using the default factory settings that MSVC++
  82. > uses in things like the options, environment, etc.  The ONLY change I've made
  83. > is to smart indent my right block bracket so it lines up with the code, but I
  84. > doubt that is the cause of my problem.  Further, I have downloaded and
  85. > installed the latest patches.
  86. >   Your help is appreciated.
  87. > Sincerely,
  88. >   Mike Billard
  89. >   billardm@csus.edu
  90.  
  91. Mike, there are two possibilities for this behavior:
  92.  
  93. 1) simply add an empty line at the end of your ctest.h.
  94.  
  95.    If this doesn't help,
  96. 2) Try to get rid of precompiled headers (in Project Setting, C++ 
  97.    Tab)and rebuild the project
  98.  
  99. I am pretty shure that adding another CR at the end of the header will 
  100. help.
  101.  
  102. Max.
  103.